/*
 * Project Beknyou
 * Copyright (c) 2010-2011 Saint Paul College, All Rights Reserved
 * Redistributions in source code form must reproduce the above
 * Copyright and this condition.
 * The contents of this file are subject to the GNU General Public
 * License, Version 2 (the "License"); you may not use this file
 * except in compliance with the License. A copy of the License is
 * available at http://www.opensource.org/licenses/gpl-license.php.
 */
package com.benkyou.server.listeners;

import com.benkyou.common.messages.PlayerDisconectMessage;
import com.benkyou.server.GameServer;
import com.jme3.network.ConnectionListener;
import com.jme3.network.HostedConnection;
import com.jme3.network.Server;

/**
 *
 * @author Austin Allman
 */
public class BenkyouClientConnectionListener implements ConnectionListener {

    private GameServer gameServer;

    public BenkyouClientConnectionListener(GameServer gameServer) {
        this.gameServer = gameServer;
    }

    public void connectionAdded(Server server, HostedConnection conn) {
        String uuid = "unique newyork" + System.currentTimeMillis() + conn.getId();
        conn.setAttribute("UUID", uuid);
    }

    public void connectionRemoved(Server server, HostedConnection conn) {
       
       gameServer.removePlayerByUUID((String)conn.getAttribute("UUID"));
       gameServer.syncPlayers();
       gameServer.getMyServer().broadcast(new PlayerDisconectMessage((String)conn.getAttribute("UUID")));
        
    }
}
